query parameters with question mark and Query types
#[tokio::main]
async fn main() {
let routes_hello = Router::new().route(
"/hello", // path
axum::routing::get(handler_hello),
);
let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
println!("@@@@@ LISTENING ON {}", addr);
axum::Server::bind(&addr)
.serve(routes_hello.into_make_service())
.await
.unwrap();
}
async fn handler_hello(Query(params): Query<HelloParams>) -> impl IntoResponse {
println!("@@@@@ {:<12} - {params:?}", "HANDLER");
let name = params.name.unwrap_or("World".to_string());
Html(format!("Hello <b>{name}!!!</b>"))
}